package com.wzy.java;

import java.time.LocalDate;
import java.time.Period;

public class test15 {
    public static void main(String[] args) {
        //算两个日期间隔多少天，计算间隔多少年，多少月
        LocalDate date1 = LocalDate.parse("1998-08-15");
        LocalDate date2 = LocalDate.parse("2021-08-15");
        Period period = Period.between(date1, date2);
        System.out.println("date1 到 date2 相隔："
                + period.getYears() + "年"
                + period.getMonths() + "月"
                + period.getDays() + "天");
    }
}
